<%@page
	import="com.zhangwoo.spider.client.process.SpiderThreadValidation"%>
<%@page import="com.meiya.common.string.StringUtil"%>
<%@page
	import="com.zhangwoo.spider.server.*,java.util.*,com.zhangwoo.spider.po.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title></title>
</head>
<body>
<%
	String url = request.getParameter("url");
	String xml = request.getParameter("xml");
	String header = request.getParameter("header");
	String met = request.getParameter("met");
	String rt = request.getParameter("rt");
	Object[] os = new Object[] { new ArrayList<UrlRequest>(),
			new ArrayList<Conversation>() };
	if (!StringUtil.isEmpty(url)) {
		Task k=new Task("000");
		k.setRunable(rt);
		UrlRequest u = new UrlRequest(url, k);
		u.setMethod(met);
		String[] hs=header.split("\n");
		Map<String,String> hh=new HashMap<String,String>();
		for(String h : hs){
			hh.put(h.split(":")[0],h.substring(h.indexOf(":")+1));
		}
		u.setHeader(hh);

		os = new SpiderThreadValidation(u, xml).codeProcessValidation();
	}
	if(os==null){
		os = new Object[] { new ArrayList<UrlRequest>(),
				new ArrayList<Conversation>() };
	}
%>
<script type="text/javascript">
function showTr(){
	alert(document.getElementById("headertr").style.display)
	if(document.getElementById("headertr").style.display=="block")
		document.getElementById("headertr").style.display="none";
	else
		document.getElementById("headertr").style.display="block";
	document.getElementById("headertr").style.display="block";
}
</script>
<form action="validation.jsp" method="post">
<table width="100%" border=1>
	<tr>
		<td>测试URL：<input size="150" name="url" value="<%=StringUtil.nullToSpace(url)%>">
		<select name="met">
		<option value="get">get</option>
		<option value="post">post</option>
		</select>
		</td>
	</tr>
	<tr>
		<td>是否单次运行任务：<select name="rt" ><option value="1" <%=("2".equals(StringUtil.nullToSpace(rt))?"":"selected") %>>普通运行</option><option value="2" <%=("2".equals(StringUtil.nullToSpace(rt))?"selected":"") %>>首次特殊运行</option></select></td>
	</tr>
	<tr>
		<td>测试XML：<textarea name="xml" cols="180" rows="20"><%=StringUtil.nullToSpace(xml)%></textarea></td>
	</tr>
	<tr>
		<td>测试Header
		</td>
	</tr>
	<tr>
		<td><textarea name="header" cols="180" rows="7"><%=StringUtil.nullToSpace(header)%></textarea></td>
	</tr>
	<tr>
		<td><input type="submit" /></td>
	</tr>
</table>
</form>
<table width="100%" border=1>
	<tr>
		<td>结果展示</td>
	</tr>
	<tr>
		<td>获取链接:<br />
		<%
			for (UrlRequest u : (List<UrlRequest>) os[0]) {
				out.println(u.getTitle()+":"+u.getUrl()+"<br>");
			}
		%>
		</td>
	</tr>
	<tr>
		<td>获取结果:<br />
		<table width="100%" border=1>
			<tr>
				<td>标题</td>
				<td>用户</td>
				<td>时间</td>
				<td>内容</td>
			</tr>
			<%
				for (Conversation u : (List<Conversation>) os[1]) {
					out.println("<tr><td>" + u.getTitle() + "</td><td>"
							+ u.getAuthor() + "</td><td>" + u.getPublishTime()
							+ "</td><td>" + u.getContent() + "</td></tr>");

				}
			%>
		</table>
		</td>
	</tr>
</table>
</body>
</html>